package com.chenjl.api;

import kafka.admin.TopicCommand;

import org.junit.Test;
/**
 * 测试Topic API，直接操作zk目录对topic进行操作
 * 		topic 信息在 zookeeper  /config/topics 目录下
 * 		
 * 		/brokers/topics/ids
 * 		/brokers/topics/__consumer_offsets
 * 		
 * 
 * 2016-9-12 14:35:47
 * @author chenjinlong
 */
public class TestOnTopicCmd {
	@Test
	public void createTopic() {
		String[] array = new String[] {
				"--create",
				"--zookeeper","192.168.245.129:2181",
	            "--partitions","3",//分区数
	            "--replication-factor","1",//副本数
	            "--topic","topic02"
	        };
		
		TopicCommand.main(array);
	}
	@Test
	public void listTopic() {
		String[] array = new String[] {
				"--list",
				"--zookeeper","192.168.245.129:2181"
	        };
		
		TopicCommand.main(array);
	}
	@Test
	public void viewOne() {
		//查看指定topic信息
		String[] array = new String[] {
				"--describe",
				"--zookeeper","192.168.245.129:2181",
				"--topic","topic01"
	        };
		
		TopicCommand.main(array);
	}
	@Test
	public void deleteTopic() {
		//Topic topic01 is marked for deletion.
		//Note: This will have no impact if delete.topic.enable is not set to true.
		//delete.topic.enable=true
		String[] array = new String[] {
				"--delete",
				"--zookeeper","192.168.245.129:2181",
				"--topic","topic02"
	        };
		
		TopicCommand.main(array);
	}
}